/* 
 * Copyright (c) 2010 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.enterprise.gsa.keymatch;

import com.google.enterprise.gsa.PromotedResult;

/**
 * A simple wrapper class for KeyMatch information. See
 * <a
 * href="http://code.google.com/apis/searchappliance/documentation/62/help_gsa/serve_keymatch.html">
 * KeyMatch</a>
 */
public class KeyMatch extends PromotedResult {

  /* The type of KeyMatch: KeywordMatch, PhraseMatch, ExactMatch */
  private String keyMatchType;
  
  /**
   * Creates a KeyMatch object with the given information
   * 
   * @param query The query that triggers this KeyMatch
   * @param url The URL that this KeyMatch points to
   * @param keyMatchType {@code KeywordMatch, PhraseMatch, ExactMatch}
   * @param title The descriptive title of this KeyMatch
   */
  public KeyMatch(String query, String url, String keyMatchType, String title){
    super(query, url, title);    
    this.keyMatchType = keyMatchType;    
  }

  /**
   * Gets the type of KeyMatch
   *
   * @return {@code KeywordMatch, PhraseMatch, ExactMatch}
   */
  public String getKeyMatchType() {
    return keyMatchType;
  }

  /**
   * 
   * @param keyMatchType one of {@code KeywordMatch, PhraseMatch, ExactMatch}
   */
  public void setKeyMatchType(String keyMatchType) {
    this.keyMatchType = keyMatchType;
  }
  
  /**
   * A {@code String} in the format of
   * {@code Query/URL/KeyMatch Type/Descriptive Title}
   */
  @Override
  public String toString() {
    final char delim = '/';
    return getQuery() + delim + getUrl() + delim + keyMatchType + delim + getTitle();
  }  
}